package cn.zhbitzwz.com.testappbyid.AppList;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;


import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import cn.zhbitzwz.com.testappbyid.R;

public class Appinfomain extends AppCompatActivity {
    Timer timer=new Timer();       //****
    Handler hendler= new Handler(){
        public void handleMessage(Message mag){
            switch (mag.what){
                case 1:
                    appinfos=appinfoService.getAppinfos();
                    break;
            }
            super.handleMessage(mag);
        }

    };
    //    private List<Appinfo> appinfoList = new ArrayList<>();
    AppinfoService appinfoService ;
    List<Appinfo> appinfos ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_appinfomain);
        appinfoService = new AppinfoService(Appinfomain.this);
        appinfos = appinfoService.getAppinfos();
        AppinfoAdapter adapter = new AppinfoAdapter(Appinfomain.this,
                R.layout.appinfo_item, appinfos);
        ListView listView = (ListView) findViewById(R.id.list_view);
        listView.setAdapter(adapter);
        timer.schedule(new RTask(),1000,10000);//***
    }
    class RTask extends TimerTask {
        public void run(){
            Message msg=new Message();
            msg.what=1;
            hendler.sendMessage(msg);
        }
    }//***

}

